package cn.qiao.rabbitmq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DirectExchangeConfig {
 
    public static final String DIRECT_QUEUE = "directQueue";
    public static final String DIRECT_EXCHANGE = "directExchange";
    public static final String TOPIC_EXCHANGE = "topicExchange";
    public static final String DIRECT_ROUTING_KEY = "direct";
    public static final String DIRECT_ROUTING_KEY1 = "direct1";


    //绑定键
    public final static String man = "topic.man";
    public final static String woman = "topic.woman";
 
    @Bean
    public Queue directQueue() {
        return new Queue(DIRECT_QUEUE, true);
    }
 
    @Bean
    public Queue manQueue() {
        return new Queue(man);
    }
    @Bean
    public Queue womanQueue() {
        return new Queue(woman);
    }
 
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(DIRECT_EXCHANGE, true, false);
    }
    @Bean
    public TopicExchange topicExchange() {
        return new TopicExchange(TOPIC_EXCHANGE, true, false);
    }
 
    @Bean
    public Binding bindingDirectExchange(Queue directQueue, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue).to(directExchange).with(DIRECT_ROUTING_KEY);
    }

    @Bean
    public Binding bindingDirect1Exchange(Queue directQueue, DirectExchange directExchange) {
        return BindingBuilder.bind(directQueue).to(directExchange).with(DIRECT_ROUTING_KEY1);
    }
 
    @Bean
    public Binding bindingManQueueExchange() {
        return BindingBuilder.bind(manQueue()).to(topicExchange()).with(man);
    }

    @Bean
    public Binding bindingWomanQueueExchange() {
        return BindingBuilder.bind(womanQueue()).to(topicExchange()).with("topic.#");
    }
 
}